fix(steami_config): Simplify calibrate_temperature for frozen drivers.#249
fix(steami_config): Simplify calibrate_temperature for frozen drivers.#249
Conversation
There was a problem hiding this comment.
Pull request overview
This PR simplifies the steami_config temperature calibration example now that sensor drivers can be frozen into firmware, removing previous RAM-management workarounds.
Changes:
- Replaced dynamic imports /
sys.modules.pop()/gc.collect()with direct imports. - Refactored calibration to iterate over a static list of sensors.
- Updated the module docstring to note the requirement for frozen-firmware workflow (
make firmware && make deploy).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Calibrate each sensor | ||
| sensors = [ | ||
| ("hts221", HTS221(i2c)), | ||
| ("wsen_pads", WSEN_PADS(i2c)), | ||
| ("lis2mdl", LIS2MDL(i2c)), | ||
| ("ism330dl", ISM330DL(i2c)), | ||
| ] |
There was a problem hiding this comment.
sensors is built with already-constructed driver instances. This means if any sensor constructor raises (device missing / wrong address / I2C error), the script aborts before calibrating any sensors, and it also keeps all sensor instances alive at once. Consider storing (name, DriverClass) (or a small factory) and instantiating each sensor inside the loop (and del it after) so one failure doesn’t prevent calibrating the others and to keep RAM use bounded.
There was a problem hiding this comment.
Acknowledged. With frozen drivers, all instances share the same ROM code so RAM impact is minimal. We'll keep the current approach (all instantiated upfront) and revisit if hardware tests show RAM issues (#175).
| sensor = cls(i2c) | ||
| if config_name == "ism330dl": | ||
| sleep_ms(200) | ||
| for name, sensor in sensors: |
There was a problem hiding this comment.
The “Verification (after reload)” loop reuses the same sensor instances created before config.save()/reload. This doesn’t match the real next-boot scenario and can hide issues that only show up on fresh instances (driver init state, cached calibration fields, etc.). Recreate new sensor instances for verification after config2.load() (and apply the same ISM330DL warm-up delay if it’s needed on first read).
| for name, sensor in sensors: | |
| verification_sensors = [ | |
| ("hts221", HTS221(i2c)), | |
| ("wsen_pads", WSEN_PADS(i2c)), | |
| ("lis2mdl", LIS2MDL(i2c)), | |
| ("ism330dl", ISM330DL(i2c)), | |
| ] | |
| for name, sensor in verification_sensors: | |
| if name == "ism330dl": | |
| sleep_ms(200) |
There was a problem hiding this comment.
Good point. Fixed in 1836fb4 — verification now creates fresh sensor instances to simulate a real reboot.
## [0.1.2](v0.1.1...v0.1.2) (2026-03-26) ### Bug Fixes * **steami_config:** Simplify calibrate_temperature for frozen drivers. ([#249](#249)) ([81f9588](81f9588))
|
🎉 This PR is included in version 0.1.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
Simplify
calibrate_temperature.pyexample by removing RAM management hacks that were needed before drivers were frozen into the firmware.Closes #248
Changes
Removed:
sys.modules.pop()/__import__()pattern for loading/unloading drivers one at a timegc.collect()calls between sensor readsReplaced with:
from xxx import XXXimports (drivers are in ROM, not RAM)(name, sensor_instance)tuplesmake firmware && make deploy)Related
Test plan
make lintpassesmake run SCRIPT=lib/steami_config/examples/calibrate_temperature.pyon hardware